import format from '@dfeidao/atom-web/dt/format';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p002 from './p002';
import p003 from './p003';
interface Par extends Event {
	page_no: number;
}
export default async function a012(fd: IFeidaoAiBrowserComponent, e: Par) {
	// todo
	// 重新渲染 p002
	const a1 = get(fd,'staff_no1');
	// 表名	notice
	const res1 = await nodejs<{res: Array<{inform_no: string, inform_title: string, inform_content: string,
		notification_time: number, pub_user_no: string, pub_user_name: string}>; res3: Array<{inform_no: string, inform_title: string, inform_content: string,
			notification_time: number, pub_user_no: string, pub_user_name: string}>; res1: number; res4: number}>('notification-notice/zj-000001/s005',
		{
			filter: {
				pn: e.page_no,
				a: a1
			}
		});
		// console.log('分页',res1.res);
		// console.log('shuliang',res1.res1);

	const arr1 = Array();
	const num = res1.res1[0].inform_title ;
	for (let i = 0; i < num; i++) {
		arr1.push(res1.res3[i].inform_no);
	}
	const newres1 = res1.res.map((n) => {
		return { ...n, receive_time: format(n.notification_time, 2) };
	});
		const arr3 = Array();
	for (let i = 0; i < arr1.length; i++) {
	const res3 = await nodejs<{ dt: Array<{ inform_no: string, pub_user_no: string, pub_user_name: string }> }>('notification-notice/zj-000001/s006',
			{
				filter: {
					arr: arr1[i]
				}
			});
		arr3.push(res3.dt);
	}
	const arr5 = Array();
	for (let i = 0; i < arr3.length; i++) {
		let strName = "";
		for (let j = 0; j < arr3[i].length; j++) {
			if (arr3[i].length === 0) {
				strName = "";
			}
			if (arr3[i].length === 1) {
				strName += arr3[i][j].pub_user_name;
			}
			if (arr3[i].length === 2) {
				if (j === 1) {
					strName += arr3[i][j].pub_user_name;
				} else {
					strName += arr3[i][j].pub_user_name + ",";
				}
			}
			if (arr3[i].length === 3) {
				if (j === 2) {
					strName += arr3[i][j].pub_user_name;
				} else {
					strName += arr3[i][j].pub_user_name + ",";
				}
			}
			if (arr3[i].length > 3) {
				if (j === 2) {
					strName += arr3[i][j].pub_user_name + "...";
				}
				if (j < 2) {
					strName += arr3[i][j].pub_user_name + ",";
				}
			}
		}
		arr5.push(strName);

	}
	let a = 0;
	const newarr = newres1.map((n) => {
		n.pub_user_name = arr5[a];
		a++;
		return n;
	});

	if (newres1.length > 0) {
		render(fd, newarr, p002, "p002", "inner");
	} else {
		render(fd, "", p003, 'p003', 'inner');
	}

}
